package com.chuanyang.driverh.mainhome;


import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.chuanyang.driverh.R;
import com.chuanyang.driverh.base.BaseTitleActivity;
import com.chuanyang.driverh.response2.ResultGetOrder;
import com.chuanyang.driverh.responseresult.OrderDatailResult;
import com.chuanyang.driverh.utils.ConstUtil;
import com.chuanyang.driverh.utils.DialogUtil;
import com.chuanyang.driverh.utils.PrintUtil;
import com.chuanyang.driverh.utils.SharedPrefUtil;
import com.chuanyang.driverh.utils.net.JsonGenericsSerializator;
import com.chuanyang.driverh.utils.net.MyCallback;
import com.chuanyang.driverh.utils.net.MyHttpUtil;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;


public class GetOrderSuccessActivity extends BaseTitleActivity {
    private TextView tv_see_detail;
    private TextView tv_cancel;
//    PendOrderData.DataBean data;
    private ResultGetOrder.PageEntity.OrderEntity data;

    @Override
    protected int getContentResId() {
        return R.layout.home_act_get_order_success;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        tv_see_detail=(TextView)findViewById(R.id.tv_see_detail);
        tv_cancel=(TextView)findViewById(R.id.tv_cancel);
    }

    @Override
    protected void initData() {
        setBackImg();
        getTitleTextView().setText("申请成功");
        data= (ResultGetOrder.PageEntity.OrderEntity) getIntent().getSerializableExtra("data");
    }

    @Override
    protected void initListener() {
        tv_see_detail.setOnClickListener(this);
        tv_cancel.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.tv_see_detail:
                Intent intent=new Intent(activityContext,OrderDetailRceiveActivity.class);
                intent.putExtra("data",data.getOrderId()+"");
                intent.putExtra("type","0");
                startActivity(intent);
                finish();
                break;
           /* case R.id.tv_cancel:
                if (data!=null){
                    //放弃
                    orderSheve(data.getOrderId()+"2","",data.getFleetId()==0?"1":"2");
                }
                break;
*/
        }
    }
    //订单搁置
    private void orderSheve(String orderId,String oprateType,String pushType) {//操作类型（1：接单，2：拒绝，3：搁置）
        DialogUtil.showLoadingDialog(activityContext, "加载中...");
        Map<String, String> params = new HashMap<String, String>();
        params.put("driverId", SharedPrefUtil.getUserId());
        params.put("orderId", orderId);
        params.put("operate", oprateType);
        params.put("type", pushType);//类型（1：个人，2：车队）
        MyHttpUtil.orderShelve(activityContext, params, new MyCallback<OrderDatailResult>(activityContext, new JsonGenericsSerializator()) {
            @Override
            public void onFail(Call call, Exception e, int id) {
                e.printStackTrace();
                PrintUtil.toast(activityContext, "网络异常，请稍后再试");
            }

            @Override
            public void onSuccess(OrderDatailResult result, int id) {
                if (result.getCode() == ConstUtil.OK) {
                    PrintUtil.toast(activityContext, "操作成功");
                } else {
                    PrintUtil.toast(activityContext, result.getMsg());
                }
            }
        });
    }
}
